import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LogoutServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html;charset=big5");

		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		session.invalidate();// 使Session失效，調用User對象的valueUnbound()方法，從用戶列表刪除用戶

		PrintWriter out = response.getWriter();
		out.println("<HTML>");
		out.println("<HEAD><TITLE>退出登錄</TITLE></HEAD>");
		out.println("<BODY>");
		out.print(user.getName() + ",你已退出登錄<br>");
		out.print("<a href=login.html>重新登錄</a>");
		out.println("</BODY>");
		out.println("</HTML>");
		out.close();
	}

}
